<template>
  <!-- 项目配置模态框 -->
  <el-dialog
    title="项目配置"
    :visible.sync="DialogShow"
    width="50%"
    :before-close="closeDialog"
  >
    <span class="main"
      ><el-form
        ref="createdFormRef"
        :label-position="labelPosition"
        label-width="80px"
        :model="form"
        inline
        :rules="rules"
      >
        <el-form-item label="部署地址" prop="en_name">
          <el-input v-model="form.deploy_address"></el-input>
        </el-form-item>
        <el-form-item label="描述" prop="cn_name">
          <el-input v-model="form.description"></el-input>
        </el-form-item>
      </el-form>
    </span>
    <span slot="footer" class="dialog-footer">
      <el-button @click="closeDialog">取 消</el-button>
      <el-button type="warning" plain @click="resetForm">重 置</el-button>
      <el-button type="primary" @click="addPersonnel" style="width: 200px"
        >创 建</el-button
      >
    </span>
  </el-dialog>
</template>

<script>
export default {
  props: ["DialogShow", "form"],
  data() {
    return {
      labelPosition: "right",
      // 验证规则
      rules: {
        address: [
          {
            required: true,
            trigger: "blur",
            message: "git库路径不能为空",
          },
        ],
        to_address: [
          {
            required: true,
            trigger: "blur",
            message: "clone到本地某个位置",
          },
        ],
      },
    };
  },
  methods: {
    // 创建爬虫
    addPersonnel() {
      this.$refs.createdFormRef.validate((valid) => {
        if (!valid) return;
        delete this.form.reptileChildren;
        delete this.form.taskChildren;
        this.$http.post("/git/config", this.form).then((res) => {
          console.log(res);
          if (res.status == 200) {
            this.$refs.createdFormRef.resetFields();
            this.$message.success("创建成功");
            this.closeDialog("1");
          } else {
            this.$message.error("创建失败");
          }
        });
      });
    },
    resetForm() {
      this.$refs.createdFormRef.resetFields();
    },
    // 关闭弹出框
    closeDialog(t) {
      this.$emit("closeDialog", t);
    },
  },
};
</script>

<style lang='less' scoped>
</style>